package com.task.common.enums;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.util.ObjectUtils;

/**
 * @Author 迪迦.
 * @Date 2023/5/18 17:41
 */
public enum DataFileTypeEnum {
  SCRIPT(0, "script", "", false),
  DATA(1, "data", "", true),
  REFERER(2, "referer", "", true),

  ;

  private Integer info;
  private String displayName;
  private String msg;
  private boolean typeCheck;


  DataFileTypeEnum(Integer info, String displayName, String msg, boolean typeCheck) {
    this.info = info;
    this.displayName = displayName;
    this.msg = msg;
    this.typeCheck = typeCheck;
  }

  public static DataFileTypeEnum getEnumByInfo(int info) {
    if (!ObjectUtils.isEmpty(info)) {
      for (DataFileTypeEnum value : DataFileTypeEnum.values()) {
        if (info == value.getInfo()) {
          return value;
        }
      }
    }
    return null;
  }

  public static DataFileTypeEnum getEnumByName(String name) {
    if (!ObjectUtils.isEmpty(name)) {
      for (DataFileTypeEnum value : DataFileTypeEnum.values()) {
        if (name.equals(value.name())) {
          return value;
        }
      }
    }
    return null;
  }

  /**
   * 获取列表.
   */
  public static List<Map<String, Object>> getList() {
    List<Map<String, Object>> list = new ArrayList<>();
    for (DataFileTypeEnum value : DataFileTypeEnum.values()) {
      Map<String, Object> map = new HashMap<>();
      map.put("value", value.getInfo());
      map.put("label", value.getMsg());
      map.put("displayName", value.getDisplayName());
      list.add(map);
    }
    return list;
  }

  DataFileTypeEnum() {
  }

  public static boolean checkDataType(String dataType) {
    DataFileTypeEnum enumByName = getEnumByName(dataType);
    if (enumByName == null) {
      return false;
    }
    return enumByName.typeCheck;
  }

  public Integer getInfo() {
    return info;
  }

  public String getDisplayName() {
    return displayName;
  }

  public String getMsg() {
    return msg;
  }
}
